package cn.stylefeng.guns.modular.api;

import cn.stylefeng.guns.modular.business.model.params.OrderParam;
import cn.stylefeng.guns.modular.business.model.params.OrderQueryParam;
import cn.stylefeng.guns.modular.business.model.result.OrderResult;
import cn.stylefeng.guns.modular.business.service.OrderService;
import cn.stylefeng.guns.sys.core.util.StringUtils;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 订单表控制器
 *
 * @author jwj
 * @Date 2019-07-12 14:20:25
 */
@RestController
@RequestMapping("/gunsApi/order")
public class OrderApi extends BaseController {

    @Autowired
    private OrderService orderService;


    @ApiOperation("提交订单")
    @PostMapping("/create")
    public ResponseData create(@RequestBody OrderParam orderParam) {
        String checkStr = orderParam.checkParam();
        if (!StringUtils.isEmpty(checkStr)) {
            return ResponseData.error(700, checkStr);
        }
        orderService.create(orderParam);
        return ResponseData.success();
    }

    @ApiOperation("按条件分页查询我的订单")
    @PostMapping("/getMyOrders")
    public ResponseData getMyOrders(Page page, @RequestBody OrderQueryParam orderQueryParam) {
        Page<OrderResult> myOrders = orderService.getMyOrders(page, orderQueryParam);
        return ResponseData.success(myOrders);
    }
}


